package com.test.util;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

/**
 * 软分页URL. <br>
 * 软分页URL类.
 * <p>
 * Copyright: Copyright (c) Dec 1, 2010 5:57:28 PM
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * 
 * @author suncg@c-platform.com
 * @version 1.0.0
 */
@SuppressWarnings("unchecked")
public class SoftPaginationUrl {

	public static void replaceNav(SoftPagination pagination, HttpServletRequest request, String method) throws UnsupportedEncodingException {
		String url = request.getRequestURI() + "?";
		String previousUrl = url + "page=" + pagination.previousPage() + "&method=" + method;
		String nextUrl = url + "page=" + pagination.nextPage() + "&method=" + method;
		String firstUrl = url + "page=1" + "&method=" + method;
		String lastUrl = url + "page=" + pagination.getPageSize() + "&method=" + method;

		String skipToUrl = url + "method=" + method + "&page=";
		request.setAttribute("pagination", pagination);

		request.setAttribute("previousUrl", previousUrl);
		request.setAttribute("nextUrl", nextUrl);
		request.setAttribute("firstUrl", firstUrl);
		request.setAttribute("lastUrl", lastUrl);
		request.setAttribute("skipToUrl", skipToUrl);

		request.setAttribute("currentUrl", request.getRequestURI());
	}
}